package com.team.recruitment_management_system.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.team.recruitment_management_system.pojo.dto.message.AddChangeMessageDto;
import com.team.recruitment_management_system.pojo.entity.ChatMessage;
import com.team.recruitment_management_system.pojo.vo.chat.ChatMessageVo;
import com.team.recruitment_management_system.service.ChatMessageService;
import com.team.recruitment_management_system.mapper.ChatMessageMapper;
import com.team.recruitment_management_system.util.result.Result;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * @author 86147
 * @description 针对表【chat_message(聊天消息表)】的数据库操作Service实现
 * @createDate 2024-03-21 20:28:40
 */
@Service
public class ChatMessageServiceImpl extends ServiceImpl<ChatMessageMapper, ChatMessage>
        implements ChatMessageService {

    @Autowired
    private ChatMessageMapper chatMessageMapper;

    @Override
    public Result<Void> addChatMessage(AddChangeMessageDto addChangeMessageDto) {
        ChatMessage chatMessage = new ChatMessage();
        BeanUtils.copyProperties(addChangeMessageDto, chatMessage);
        this.save(chatMessage);
        return Result.postOk(null);
    }

    @Override
    public List<ChatMessageVo> getAll(String currentUsername, String recipientUsername) {
        List<ChatMessageVo> chatMessageVos;
        chatMessageVos = chatMessageMapper.getSenderAll(currentUsername, recipientUsername);
        return chatMessageVos;
    }
}




